<template>
	<view id="header">
		<view>
			<image src="https://cdn3.axureshop.com/demo/1509778/images/%E4%B8%AA%E4%BA%BA%E4%B8%AD%E5%BF%83/u974.svg"/>
			<text>Hello，{{user_Name}}</text>
		</view>
		<button @click="sign_out">退出</button>
	</view>
	<view id="vip">
		<view class="vip-top">
			<text style="font-weight: bolder;">VIP{{grade}}</text>
			<text style="color: #ce9a51;" @click="memberterFn">会员权益&gt;</text>
		</view>
		<view class="vip-bottom">
			<view>
				<text><text style="font-size: 28rpx;">68</text>成长值（充值可获得成长值）</text>
				<text>VIP{{grade}}</text>
			</view>
			<progress :percent="pgList" activeColor="#ce9a51" backgroundColor="#fff" stroke-width="8" border-radius= "8rpx" />
			<view>
				<text v-if="grade<5">距离VIP{{grade+1}}只差{{100-pgList}}成长值</text>
				<text v-else>VIP已升到满级</text>
				<button  @click="rechargeWalletFn">充值</button>
			</view>
		</view>
	</view>
	<view class="money">
		<view style="border-right: 1px solid #eee;">
			<text>我的余额：</text>
			<text @click="rechargeFn">{{account}}元</text>
			<text @click="rechargeFn">&gt;</text>
		</view>
		<view>
			<text>我的卡券：</text>
			<text @click="myCardFn">{{count}}张</text>
			<text @click="myCardFn">&gt;</text>
		</view>
	</view>
	<view id="type">
		<view @click="experienceCouponFn">
			<text class="iconfont icon-meituan"></text>
			<text>美团券</text>
		</view>
		<view>
			<text class="iconfont icon-zhinengchuwugui"></text>
			<text>储物柜</text>
		</view>
		<view @click="rechargeWalletFn">
			<text class="iconfont icon-yuedefuben"></text>
			<text>充余额</text>
		</view>
		<view @click="cardMarketFn">
			<text class="iconfont icon-shouye1"></text>
			<text>买卡券</text>
		</view>
		<view>
			<text class="iconfont icon-dianhua"></text>
			<text>联系商家</text>
		</view>
		<view @click='clockRecordsFn'>
			<text class="iconfont icon-kaoqindaka-xian"></text>
			<text >打卡记录</text>
		</view>
		<view @click='rankFn'>
			<text class="iconfont icon-paihangbang"></text>
			<text>排行榜</text>
		</view>
		<view @click="hellpInfo">
			<text class="iconfont icon-bangzhu"></text>
			<text>帮助</text>
		</view>
	</view>
</template>

<script setup>
	import {reactive, ref,onMounted} from 'vue'
	import http from '../../utils/http.js'
	import { onLoad, onShow,} from "@dcloudio/uni-app";
	let pgList=ref(0);
	let account=ref(0);
	let count=ref(0);
	let bigDecimal=ref(0);
	let grade=ref(0);
	let data=reactive({data:{}})
	// 用户id
	let user_Id = ref(0)
	let user_Name = ref()
	const rechargeFn=function(){
		wx.navigateTo({
		 url:"../Booking_orders_submit/Booking_orders_submit"
		})
	}
	const myCardFn = function(){
		wx.navigateTo({
		 url:"../My_card_coupons/My_card_coupons"
		})
	}
	const clockRecordsFn = function(){
		wx.navigateTo({
		 url:"../ClockRecords/ClockRecords"
		})
	}
	const rankFn = function(){
		wx.navigateTo({
		 url:"../Rank/Rank"
		})
	}
	const sign_out = function(){
		wx.navigateTo({
		 url:"../Login/Login"
		})
		uni.clearStorage();
	}
	const rechargeWalletFn = function(){
		wx.navigateTo({
		 url:"../RechargeWallet/RechargeWallet"
		})
	}
	const hellpInfo = function(){
		wx.navigateTo({
		 url:"../Compro/Compro"
		})
	}
	const cardMarketFn = function(){
		wx.navigateTo({
		 url:"../CardMarket/CardMarket"
		})	
	}
	const experienceCouponFn = function(){
		wx.navigateTo({
		 url:"../ExperienceCoupon/ExperienceCoupon"
		})	
	}
	const memberterFn = function(){
		wx.navigateTo({
		 url:"../Memberter/Memberter"
		})	
		
	}
	// 用户id
	let getUserId = function(){
		uni.getStorage({
			key: 'userId',
			success: function(res) {
				user_Id.value = res.data
				render()
			},
			fail() {
				return 
			}
		})
	}
	// 用户名字
	let getUserName = function(){
		uni.getStorage({
			key: 'name',
			success: function(res) {
				user_Name.value = res.data
				console.log('name', res.data);
			},
			fail() {
				return 
			}
		})
	}
	let render=function(){
		http({
			url:'/user/queryAccount',
			method:'get',
			params:{
				userId:user_Id.value
			}
		}).then((res)=>{
			// console.log('卡券数量',res);
			if(res.code==0){
				account.value=res.data.account
				count.value=res.data.count
				bigDecimal.value=res.data.bigDecimal
				if(bigDecimal.value<100){
					grade.value=0
					pgList.value=bigDecimal.value
				}else if(100<=bigDecimal.value<1000){
					grade.value=1
					pgList.value=bigDecimal.value/10
				}else if(1000<=bigDecimal.value<10000){
					grade.value=2
					pgList.value=bigDecimal.value/100
				}else if(10000<=bigDecimal.value<100000){
					grade.value=3
					pgList.value=bigDecimal.value/1000
				}else if(100000<=bigDecimal.value<1000000){
					grade.value=4
					pgList.value=bigDecimal.value/10000
				}else if(bigDecimal.value>=1000000){
					grade.value=5
					pgList.value=100
				}
			}else{
				console.log(res.msg);
			}
		})
	}
	onMounted(()=>{
		getUserId();
		getUserName()
	})
	// 111
	onShow(()=>{
		uni.setTabBarItem({
			index: 0,
			visible:true
		})
		uni.setTabBarItem({
			index: 1,
			visible:true
		})
		uni.setTabBarItem({
			index: 2,
			visible:true
		})
		getUserId();
		getUserName()
	})
</script>

<style lang="less" scoped>
	@import url("../../static/fonts/iconfont.css");
	#header{
		padding: 26rpx 32rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		& view{
			display: flex;
			align-items: flex-end;
			& image{
				width: 100rpx;
				height: 100rpx;
			}
			& text{
				font-size: 28rpx;
				font-weight: bolder;
				padding-bottom: 26rpx;
				padding-left: 10rpx;
			}
		}
		& button{
			width: 140rpx;
			height: 50rpx;
			border-radius: 25rpx;
			padding: 0;
			margin: 0;
			font-size: 26rpx;
			color: #fff;
			background: #c6964f;
			line-height: 50rpx;
		}
	}
	#vip{
		height: 244rpx;
		margin: 26rpx 32rpx 36rpx 32rpx;
		background: #343434;
		border-radius: 10rpx;
		padding: 34rpx 26rpx 24rpx 34rpx;
		color: #ffffff;
		& .vip-top{
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-size: 28rpx;
			margin-bottom: 48rpx;
		}
		& .vip-bottom{
			font-size: 24rpx;
			height: 150rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			& view{
				display: flex;
				justify-content: space-between;
				& button{
					width: 92rpx;
					height: 42rpx;
					border: 2px solid #ce9a51;
					border-radius: 21rpx;
					font-size: 24rpx;
					line-height: 34rpx;
					padding: 0;
					margin: 0;
					color: #ce9a51;
					background: #343434;
				}
			}
		}
	}
	.money{
		margin: 0 32rpx 38rpx 32rpx;
		height: 100rpx;
		display: flex;			
		border-radius: 10rpx;
		box-shadow: 0 0 5px #aaa;
		& view{
			width: 50%;
			height: 100rpx;
			text-align: center;
			line-height: 100rpx;
			font-size: 28rpx;
			& :nth-last-child(2){
				margin-right: 10rpx;
				color: #ce9a51;
			}
			& :nth-child(3){
				color: #ce9a51;
			}
		}
	}
	#type{
		margin: 0 32rpx;
		height: 360rpx;
		border-radius: 10rpx;
		box-shadow: 0 0 5px #aaa;
		font-size: 26rpx;
		display: flex;
		justify-content: flex-start;
		flex-wrap: wrap;
		align-content: flex-start;
		& view{
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			align-items: center;
			height: 108rpx;
			width: 110rpx;
			margin: 44rpx 13rpx 10rpx 13rpx;
			& .iconfont{
				font-size: 62rpx;
				color: #ce9a51;
			}
		}
		
	}
</style>
